using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;

namespace MVExplorer.Shapes
{
	public class ShapeManager
	{
		List<ShapeBase> lstShapes = new List<ShapeBase>();
		private DrawingMode mode;

		public ShapeManager()
		{
			lstShapes.Add(new ShapeCircle());
			lstShapes.Add(new ShapeRectangle());
			lstShapes.Add(new ShapeArrow());
			lstShapes.Add(new ShapeText());

			mode = DrawingMode.Circle;
		}

		public System.Windows.Shapes.Shape NewShape()
		{
			ShapeBase shape = GetShape();
			return shape.CreatePreElement();
		}

		public void MoveShape(Shape element, Point from, Point to)
		{
			ShapeBase shape = GetShape();
			shape.MoveElement(element, from, to);
		}

		public UIElement GenerateResult(Shape preElement)
		{
			ShapeBase shape = GetShape();
			return shape.GenerateResultElement(preElement);
		}

		public UIElement CreateTextBoxElement()
		{
			mode = DrawingMode.Text;
			ShapeText st = GetShape() as ShapeText;
			return st.CreateNewElement();
		}

		public void SetElementToTextBox(TextBox tb)
		{
			DrawingMode modeBackup = mode;
			mode = DrawingMode.Text;
			ShapeText st = GetShape() as ShapeText;
			st.SetElementToTextBox(tb);
			mode = modeBackup;
		}

		private ShapeBase GetShape()
		{
			foreach (ShapeBase shape in lstShapes)
			{
				if (shape.ShapeMode == mode)
					return shape;
			}
			Debug.Assert(false, "No registered shape requested");
			return null;
		}

		public DrawingMode Mode
		{
			get { return mode; }
			set { mode = value; }
		}
	}
}
